<include file="Public:header" />
<body class="layout">
<div id="index" >
  <div class="head"> <img src="__ROOT__/App/Vote/Static/images/top.png"/><a href="__URL__/join?activity_id=<?php echo intval($_GET['activity_id']);?>"> <img src="__ROOT__/App/Vote/Static/images/apply.png"/></a></div>
  <include file="Public:box" />
  <div class="search-bar">
	<input type="text" placeholder="搜名字或编号" name="keywords"><input type="button"  value="搜索" id="searchbutton" onClick="ajaxSearch();"></input>
  </div>
  <!-- 首页 -->
  <div class="content">
		<!-- 搜索不到 -->
		<div class="noperson hide">查无此人</div>
		<div class="col">
		</div>
		<div class="col">
		</div>
	</div>
 
  <div id="PageCount" class="pagecount"></div>
</div>
<include file="Public:footer" /> 
<script type="text/javascript">
weixinShare({$signPackage},{$sharePackage});
var activityid = "{$_GET['activity_id']}";//活动ID
/*$(function(){
		    //提示收藏信息
	    	$(".rule").click(function(){
	    		$(".rule-fixed").show();
	    	});
	    	$(".person img").click(function(){
	    		location.href="other.html";
	    	});
	    	//投票
	    	$(".vote").click(function(){
	    		if($(this).hasClass("hasvoted")){
	    			Util.showmsg("你已经投过票了")
		    	}
		    	else{
		    		var vote=$(this).parent().find(".num")
		    		var num=parseInt(vote.text());
		    		num+=1;
		    		$(".vote").addClass("hasvoted");
		    		vote.text(num);
		    	}
	    	})
		});

*/
$(function(){
	 //提示收藏信息
	$(".rule").click(function(){
		$(".rule-fixed").show();
	});
	//加载数据分页
	getData(1, '',activityid);
    $("#PageCount").on('click','img', function () {
        var rel = $(this).attr("rel");
        if (rel) {
            getData(rel, '',activityid);
			$('html,body').animate({
				scrollTop:$('.search-bar').offset().top
			}, 800);
        }
    });
})

//搜索
function ajaxSearch() {
    keywords = $("input[name=keywords]").val();
	getData(1, keywords,activityid);
	$("#PageCount").on('click','img',function () {
		var rel = $(this).attr("rel");
		if (rel) {
			getData(rel,keywords,activityid);
		}
	});
}

var curPage = 1; //当前页码
var total, pageSize, totalPage;
function getData(page, keywords,activityid) {
	
	//alert('__APP__/'+action+'/ajaxListData');
    $.ajax({
        type: 'POST',
        url: '__URL__/ajaxListData',
        data: {
            'pageNum': page - 1,
            'keywords': keywords,
			'activity_id' : activityid
        },
        dataType: 'json',
/*		beforeSend:function(){
			$("#list").append("asfdfsdf");
		},*/
        success: function (json) {
            $(".content .col").empty();
            total = json.total; //总记录数
            pageSize = json.pageSize; //每页显示条数
            curPage = page; //当前页
            totalPage = json.totalPage; //总页数
            var list = json.list;
            if (list != "") {
                $.each(list, function (index, array) { //遍历json数据列
				var tr = '';
				if(array['state'] == 1){
					src = '/App/Vote/Static/images/404.jpg';
				}else{
					src = array['img'];
				}
				tr = ' <div class="person"><div class="person-head"><a href="__URL__/detail?id='+array['id']+'&activity_id='+array['activity_id']+'"> <img src="{$Think.config.IMG_PATH}'+src+'" class="img_logo"></a><div class="shadow-tip"> <span class="person-no">NO:'+array['id']+'</span> <span class="person-name">'+array['name']+'</span> </div></div><div class="person-foot"> <span class="num" id=votenum'+index+'>'+array['vote_num']+'</span><span>票</span><button class="vote" onclick=addvote('+array['activity_id']+','+array['id']+','+index+')>投票</button></div></div>';
             /*	tr += '  <div class="product" id="list">  <a title="" href="__URL__/detail?id='+array['id']+'&activity_id='+array['activity_id']+'"><img src="__ROOT__/App/Vote/Static/{$Think.config.IMG_PATH}'+src+'" alt="" /></a><div class="checkbox"> <input type="button" onclick=addvote('+array['activity_id']+','+array['id']+','+index+'); value="投票"><br> <label>   '+array['name']+'  </label><br>			<label>       No: '+array['id']+'  </label></div> <div class="votes" id=votenum'+index+'>已获得票数： '+array['vote_num']+'</div></div>';*/
				$minUl = getMinUl();
				$minUl.append(tr);
                   
                });
            }else{
				$(".noperson").removeClass('hide');
			}
			
        },
        complete: function () { //生成分页条
            getPageBar();
        },
        error: function () {
            Util.showmsg("数据加载失败");
        }
    });
}

//获取分页条

function getPageBar() {
	var pageStr = "<div class='prev-next'> ";
    //页码大于最大页数 
    if (curPage > totalPage) curPage = totalPage;
    //页码小于1 
   if (curPage < 1) curPage = 1;
  //  pageStr = "<span>共" + total + "条</span><span>" + curPage + "/" + totalPage + "页</span>";
    if (totalPage > 1) {
        //如果是第一页 
        if (curPage == 1) {
			pageStr += " <img src='__ROOT__/App/Vote/Static/images/prev.png' class='prev'  />";
            //pageStr += "<span>首页</span><span>上一页</span>";
			//pageStr += "";
        } else {
           // pageStr += "<span><a href='#ll' rel='1'>首页</a></span> <span><a href='#ll' rel='" + (curPage - 1) + "'>上一页</a></span>";
			pageStr += "<img src='__ROOT__/App/Vote/Static/images/prev.png' class='prev'  rel='" + (parseInt(curPage - 1)) + "'/>";
        }

        //如果是最后页 
        if (curPage >= totalPage) {
			pageStr += " <img src='__ROOT__/App/Vote/Static/images/next.png' class='next'  />";
            //pageStr += "<span>下一页</span><span>尾页</span>";
        } else {
            //pageStr += "<span><a class='_ajaxpage' href='#ll' rel='" + (parseInt(curPage) + 1) + "'> 下一页</a></span><span><a href='#ll' rel='" + totalPage + "'>尾页</a></span> ";
			pageStr += "<img src='__ROOT__/App/Vote/Static/images/next.png' class='next'   rel='" + (parseInt(curPage) + 1) + "'>";
        }
    }
	pageStr +="</div>";
    $("#PageCount").html(pageStr);
}

//投票
function addvote(activityid,userid,key){
	$.getJSON('__URL__/subVote', {activityid:activityid,userid:userid}, function(json){
		if(json.status ==1){
			$("#votenum"+key).html(json.data);
			 $.get("__URL__/joinlist", function(result){
					$("#join").html(result);
			 });
		}else{
			Util.showmsg(json.info);
		}
	})
}



function getMinUl() {
	var $arrUl = $(".content .col");
	var $minUl = $arrUl.eq(0);
	$arrUl.each(function(index, elem) {
		if ($(elem).height() < $minUl.height()) {
			$minUl = $(elem);
		}
	});
	return $minUl;
}


</script>